﻿using System.Globalization;
using Auxiliary.VecMath;
using Simple3DRedactor.Domain;

namespace SceneRedactor
{
    interface IRedactorObjectView : IObjectView
    {
        void ShowProperties(SimpleSceneRedactor redactor);

        void SaveProperties(SimpleSceneRedactor redactor);
    }

    abstract class ObjectView<T> : Simple3DRedactor.Domain.ObjectView<T>, IRedactorObjectView where T : SceneObject
    {
        protected ObjectView(T obj)
            : base(obj)
        {
        }
        
        public virtual void ShowProperties(SimpleSceneRedactor redactor)
        {
            redactor.objectNameTextBox.Text = InnerObject.Name;

            redactor.objectPositionXTextBox.Text = InnerObject.Position.X.ToString();
            redactor.objectPositionYTextBox.Text = InnerObject.Position.Y.ToString();
            redactor.objectPositionZTextBox.Text = InnerObject.Position.Z.ToString();
            redactor.activeCheckBox.Checked = InnerObject.Active;
        }

        public virtual void SaveProperties(SimpleSceneRedactor redactor)
        {
            InnerObject.Name = redactor.objectNameTextBox.Text;

            // TODO : add conversion check
            InnerObject.Position = new Vector3D(
                float.Parse(redactor.objectPositionXTextBox.Text),
                float.Parse(redactor.objectPositionYTextBox.Text),
                float.Parse(redactor.objectPositionZTextBox.Text));

            InnerObject.Active = redactor.activeCheckBox.Checked;
        }

        public override string ToString()
        {
            return InnerObject.Name;
        }
    }
}
